package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping(path = "/anno")
public class AnnoController {
    @RequestMapping(path = "/testRequestParam")
    public String testRequestParam(@RequestParam(name = "name") String username){//使用RequestParam注解就必须传加注解的属性
        System.out.println("执行完毕");
        System.out.println(username);
        return "success";
    }
    @RequestMapping(path = "/testRequestBody")
    public String testRequestBody(@RequestBody String body) {//使用RequestParam获取方法体的属性
        System.out.println("执行完毕");
        System.out.println(body);
        return "success";
    }
    @RequestMapping(path = "/testModelAttribute")
    public String testModelAttribute() {
        System.out.println("执行完毕");
        return "success";
    }
    @ModelAttribute//优先执行ModelAttribute注解的方法
    public void showUser(){
        System.out.println("执行showUser方法");
    }
}
